package com.salim.leetcode.$55;

import lombok.extern.slf4j.Slf4j;

@Slf4j
public class JumpGame {
    public boolean canJump(int[] nums) {
        if(nums.length<=1){
            return true;
        }
        boolean[] jumped = new boolean[nums.length];
        return jump(nums,0,jumped);
    }

    public boolean jump(int[] nums,int index,boolean[] jumped){
        for(int i=nums[index];i>0;i--){
            if(nums.length-1>index+i){
                if(!jumped[index + i]){
                    jumped[index+i] = true;
                    if(jump(nums,index+i,jumped)){
                        return true;
                    }
                }
            }else if(nums.length-1<=index+i){
                return true;
            }
        }
        return false;
    }

    public static void main(String[] args) {
        JumpGame j = new JumpGame();
        log.info("WildcardMatching输出结果1：{}", j.canJump(new int[]{2,3,1,1,4}));
    }


}
